package com.example.android_sqlite.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

// 继承自 SQLiteOpenHelper 来实现自己的数据库
public class MySQLite extends SQLiteOpenHelper {

    public MySQLite(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }

    /**
     * 创建数据库，onCreate方法只执行一次
     * @param db
     */
    @Override
    public void onCreate(SQLiteDatabase db) {

        /**
         * 实现的逻辑
         */

        // 创建了一张学生表
        db.execSQL("create table student( s_id integer PRIMARY KEY AUTOINCREMENT NOT NULL, s_name varchar, s_age varchar, s_sex varchar, s_like varchar)");
        // 创建了一张老师表
        db.execSQL("create table teacher( t_id integer PRIMARY KEY AUTOINCREMENT NOT NULL, t_name varchar, t_age varchar, t_sex varchar, t_teach varchar)");
        // 创建了一张教室表
        db.execSQL("create table grade( g_id integer PRIMARY KEY AUTOINCREMENT NOT NULL, g_name varchar, g_t_id varchar)");
        // 创建了一张人员组合表
        db.execSQL("create table crew( c_id integer PRIMARY KEY AUTOINCREMENT NOT NULL, g_id varchar, t_id varchar, s_id varchar)");

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}
